// 数据转dict格式
export const data2Dict = (array) => {
  if (array == undefined) return []
  return array.map((item) => {
    return {
      value: isNaN(item.value) ? item.value : +item.value,
      label: item.name,
      disabled: item.isEnabled != 1,
      desc: item.desc,
    }
  })
}

// 遴选并转换为dict数据
export const cherryPick2Dict = (data, mapper) => {
  const res = {}
  for (const key in mapper) {
    if (Object.hasOwnProperty.call(mapper, key)) {
      const mapper_key = mapper[key]
      res[key] = data2Dict(data[mapper_key])
    }
  }
  return res
}

// 系统参数转换为dict数据
export const sysParam2Dict = (data, codeList) => {
  const res = {}
  codeList.forEach((code) => {
    const key = code.replace(/\_(\w)/g, (_, letter) => letter.toUpperCase())
    res[key] = data2Dict(data[code])
  })
  return res
}

// TODO: 过滤返回值的null
